/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Ventanas.java
 *
 * Created on 24-ene-2009, 13:33:45
 */

package GUI;

import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.PrintWriter;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

/**
 *
 * @author Jaime
 */
public class Ventanas extends javax.swing.JFrame {
    private Texto texto;
    JScrollPane pScroll;
    //private Busquedas busqueda;
    //JDialog

    /** Creates new form Ventanas */
    public Ventanas() {
        initComponents();
        texto= new Texto();
        pScroll = new JScrollPane(texto.getJTextArea1(), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        getTexto().setSize(900,160);
        pScroll.setSize(Constantes.getAnchoPantalla()-330,210);
        this.setLocation(0,Constantes.getLargoPantalla()-275);
        setSize(Constantes.getAnchoPantalla()-300,250);
        getContentPane().add(pScroll);
        setVisible(true);

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

  /* public void busquedas(){
        busqueda=new Busquedas();
		busqueda.setSize(350,300);
        this.setLocation(Constantes.getLargoPantalla()-70,0);
		this.setSize(350,300);
        getContentPane().add(busqueda);
   }*/

   public void deTexto(){

        texto= new Texto();
        pScroll = new JScrollPane(texto.getJTextArea1(), JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
        getTexto().setSize(900,160);
        pScroll.setSize(915,210);
        this.setLocation(0,580);
        setSize(920,250);
        getContentPane().add(pScroll);
        setVisible(true);

   }

      public void escribeTexto(String s){
      //texto.getJTextArea1().setText(s);
      texto.getJTextArea1().setText(texto.getJTextArea1().getText() +'\n'+ s);
       Point p = new Point(0,texto.getJTextArea1().getHeight());
       pScroll.getViewport().setViewPosition(p);

      }
      public void limpiaTexto(){texto.getJTextArea1().setText("");}

    public Texto getTexto() {
        return texto;
    }

  /*  public Busquedas getBusqueda(){
        return busqueda;
    }*/



    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
	public boolean fin(){
		String[] opciones = {"Si","No"};
        saveFile();
		return JOptionPane.showOptionDialog(this,"Quiere volver a ejecutar el programa?","Fin de programa",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,null,opciones,"No")==1;
	}
    public boolean saveFile(){

	boolean ok = true;
	try{
        PrintWriter archivo = new PrintWriter("arch.log");
        archivo.print(texto.getJTextArea1().getText());
        archivo.close();
	}
	catch (Exception e){ok = false;
	}
	return ok;

}
}
